<template>
  <div></div>
</template>


<script>
export default {
  data() {
    return {
      data: "",
      code: ""
    };
  },
  mounted() {
    if (window.localStorage.getItem("token")) {
      this.$router.push({
        path: "/recruit/mine"
      });
      return false;
    }

    let code = window.location.search.split("&")[0].split("=")[1];
    this.code = code;
    this.$axios
      .post("/wap/register/weChat", {
        code: code
      })
      .then(res => {
        this.$toast(res.data.msg);
        if (res.data.data.phone == 2) {
          console.log(res.data);
          localStorage.setItem("openid", res.data.data.openid);
          localStorage.setItem("user_name", res.data.userInfo.user_name);
          localStorage.setItem("head_img", res.data.userInfo.head_img);
          this.$router.push({
            path: "/recruit/recruitwx",
            params: {
              openid: res.data.data.openid,
              code: this.code,
              user_name: res.data.userInfo.user_name,
              head_img: res.data.userInfo.head_img
            }
          });
        } else {
          window.localStorage.removeItem("token");
          window.localStorage.setItem("token", res.data.data.token);
          document.cookie = "TOKEN=" + res.data.data.token + "; path=/";

          if (localStorage.getItem("returnPath")) {
            window.location.href = localStorage.getItem("returnPath");
            localStorage.removeItem("returnPath");
            return false;
          }
          
          this.$router.push({
            path: "/recruit/mine"
          });
        }
      });
  }
};
</script>